<template>
  <div class="day_and_night">
    <div
      @click="toggleNightMode"
      :class="{ [isDay ? 'day' : 'night']: true, box: true }"
    >
      <i :class="{iconfont:true, [isDay ? 'icon-sun1' : 'icon-goodnight']:true}"></i>
    </div>
  </div>
</template>

<script>
export default {
  name: "day_night",
  data() {
    return {
      isDay: this.$store.getters.isDay,
    };
  },
  methods: {
    toggleNightMode() {
      console.log(this.isDay);
      this.isDay = !this.isDay;
      this.$store.dispatch("setIsDay", this.isDay);
    },
  },
};
</script>

<style scoped lang="scss">

.box {
  width: 56px;
  height: 26px;
  background-color: var(--box-bgcolor-day);
  border-radius: 26px;
  overflow: hidden;
  position: relative;
  border:2px solid var(--icon-bgcolor-day);
  box-sizing: content-box;
  i {
    width: 26px;
    height: 26px;
    display: block;
    font-size: 18px;
    font-weight: 500;
    text-align: center;
    line-height: 26px;
    color: var(--icon-color-day);
    position: absolute;
    left: 0;
    top: 0;
    transition: all 0.5s ease-in-out;
  }
}
.box::before {
  width: 26px;
  height: 26px;
  content: "";
  background-color: var(--icon-bgcolor-day);
  // background-color: #339999;
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  transition: all 0.5s ease-in-out;
}
.box.night::before {
  left: 30px;
  background-color: var(--icon-bgcolor-night);
}
.box.night {
  background-color: var(--box-bgcolor-night);
  border:2px solid #546776;
  i {
    color:var(--icon-color-night);
    left: 30px;
  }
}
</style>